//
//  YongHu.m
//  SeeTheWorld
//
//  Created by dllo on 16/2/29.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "YongHu.h"
#import "ModelOfYongHu.h"
#import "PCH.pch"
#import <UIImageView+WebCache.h>


@interface YongHu ()

@property (nonatomic, retain)UIImageView *touXiang;
@property (nonatomic, retain)UILabel *labelOfName;
@property (nonatomic, retain)UILabel *labelOfTrip;

@property (nonatomic, retain)NSMutableAttributedString *mAttStri;

@end

@implementation YongHu

- (void)dealloc {
    [_touXiang release];
    [_labelOfName release];
    [_labelOfTrip release];
    [_mAttStri release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.touXiang = [[UIImageView alloc] init];
        [self.contentView addSubview:self.touXiang];
        [_touXiang release];
       
        self.labelOfName = [[UILabel alloc] init];
        [self.contentView addSubview:self.labelOfName];
        [_labelOfName release];
        self.labelOfName.font = [UIFont systemFontOfSize:20];
        self.labelOfName.dk_textColorPicker = DKColorWithRGB(0x343434, 0xffffff);

        self.labelOfTrip = [[UILabel alloc] init];
        [self.contentView addSubview:self.labelOfTrip];
        [_labelOfTrip release];
        self.labelOfTrip.dk_textColorPicker = DKColorWithRGB(0x343434, 0xffffff);

    }
    
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.touXiang.frame = CGRectMake(5, 5, self.contentView.frame.size.width / 5, self.contentView.frame.size.height - 10);
    self.touXiang.layer.cornerRadius = self.touXiang.frame.size.width / 2;
    self.touXiang.layer.masksToBounds = YES;
    
    self.labelOfName.frame = CGRectMake(5 + self.contentView.frame.size.width / 5 + 5, 5, self.contentView.frame.size.width / 5 * 4 - 30, (self.contentView.frame.size.height - 15) / 2);
    
    self.labelOfTrip.frame = CGRectMake(5 + self.contentView.frame.size.width / 5 + 5, 10 + (self.contentView.frame.size.height - 15) / 2, self.contentView.frame.size.width / 5 * 4 - 30, (self.contentView.frame.size.height - 15) / 2);
 
}

- (void)passModel:(ModelOfYongHu *)model {
    
       [self.touXiang sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:[UIImage imageNamed:@"1f178a82b9014a90e9109296ad773912b31beeeb"]];
    self.labelOfTrip.text = model.latest_publish_trip_name;
    
    /** 关键字高亮. */
    self.mAttStri = [[NSMutableAttributedString alloc] initWithString:model.name];
    NSRange range = [model.name rangeOfString:model.text];
    [self.mAttStri addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range];
    self.labelOfName.attributedText = self.mAttStri;
}










@end
